import * as types from "../types/serviceInfoTypes";

const initialState = {
  loading: false,
  initing: true,
  error: undefined,
  serviceInfo: [],
  serviceId: 0,
  imageList: [],
  serviceItem: undefined,
  curServiceWayIndex: 0,
};

export default function serviceInfoReducer(state = initialState, action) {
  switch (action.type) {
    case types.SERVICEINFO_INITING:
      return {
        ...state,
        initing: true,
        serviceId: action.serviceId,
      };
    case types.SERVICEINFO_DONE:
      return {
        ...state,
        initing: false,
        loading: false,
        serviceInfo: action.serviceInfo,
        imageList: action.imageList,
      };
    case types.SERVICEINFO_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.SERVICEINFO_CHANGESERVICEWAY:
      return {
        ...state,
        initing: false,
        loading: false,
        curServiceWayIndex: action.curServiceWayIndex,
      };
    case types.SERVICEINFO_CHANGEDEVICEMODEL:
      // facility_id, deviceModel.facility_name  facilityId, facilityName
      return {
        ...state,
        initing: false,
        loading: false,
        serviceItem: action.serviceItem,
      };
    case types.SERVICEINFO_SERVICEINFOUNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
